package cn.xm.lingshi.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.xm.lingshi.dao.CityDao;
import cn.xm.lingshi.pojo.Dz_ChengShi;
import cn.xm.lingshi.utlis.BaseDao;

/**
 *城市数据访问层
 **/
public class CityDaoImpl extends BaseDao implements CityDao {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List<Dz_ChengShi> list(Integer id) {
		String preparedSql = "SELECT cs_id,sh_id,cs_name FROM dz_chengshi WHERE sh_id=?";
		Object prm[] = { id };
		Dz_ChengShi cs = null;
		ResultSet rs = null;
		List list = null;
		try {
			rs = super.executeQuery(preparedSql, prm);
			if (rs != null) {
				list = new ArrayList<Dz_ChengShi>();
				while (rs.next()) {
					cs = new Dz_ChengShi();
					cs.setCs_id(rs.getInt(1));
					cs.setSh_id(rs.getInt(2));
					cs.setCs_name(rs.getString(3));
					list.add(cs);
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public Dz_ChengShi chaXun(Integer sid, Integer cid) {
		String preparedSql = "SELECT cs_id,sh_id,cs_name FROM dz_chengshi WHERE sh_id=? AND cs_id=?";
		Object prm[] = { sid,cid };
		Dz_ChengShi cs = null;
		ResultSet rs = null;
		try {
			rs = super.executeQuery(preparedSql, prm);
			if (rs != null) {
				if (rs.next()) {
					cs = new Dz_ChengShi();
					cs.setCs_id(rs.getInt(1));
					cs.setSh_id(rs.getInt(2));
					cs.setCs_name(rs.getString(3));
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return cs;
	}

}
